home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / zcpp_jae.zip / TEMPSAMP.CPP < prev    next >
C/C++ Source or Header  |  1991-04-26  |  2KB  |  55 lines

  1. /*
  2.  
  3.  
  4.  Copyright (C) 1990 Texas Instruments Incorporated.
  5.  
  6.  Permission is granted to any individual or institution to use, copy, modify,
  7.  and distribute this software, provided that this complete copyright and
  8.  permission notice is maintained, intact, in all copies and supporting
  9.  documentation.
  10.  
  11.  Texas Instruments Incorporated provides this software "as is" without
  12.  express or implied warranty.
  13.  
  14.  
  15.  */
  16.  
  17. // The "#pragma defmacro" is a COOL extension to the standard  ANSI C processor
  18. // that allows  a programmer to  define macro  extensions to the  language. All
  19. // COOL  macros   have  been  incorporated  into  the preprocessor   itself  to
  20. // facilitate extra speed and efficiency. User defined  extensions are searched
  21. // for on the include file path.
  22.  
  23. #pragma defmacro MACRO "macro" delimiter=} recursive
  24. #pragma defmacro template "template" delimiter=}
  25. #pragma defmacro DECLARE "declare" delimiter=> recursive lines
  26. #pragma defmacro IMPLEMENT "implement" delimiter=> recursive lines
  27.  
  28. extern void* error (char*);
  29.  
  30. template<class T> class Vector<T> {
  31.     T* v;
  32.     int sz;
  33. public:
  34.     Vector<T>(int);
  35.     T& operator[](int);
  36.     inline T& elem(int i) { return v[i]; }
  37. };
  38.  
  39. template<class T>
  40. T& Vector<T>::operator[](int i)
  41. {
  42.     if (i<0 || sz<=i) error("vector: range error");
  43.     return elem(i);
  44. };
  45.  
  46. template<class T>
  47. Vector<T>::Vector<T>(int size)
  48. {
  49.     v = (T *)new(T[size]);
  50. };
  51.  
  52. DECLARE Vector<char*>;   // create definitions for a vector of strings
  53. IMPLEMENT Vector<char*>; // generate code to support vector of strings
  54. Vector<char*> vs(30);     // declare a vector of 30 strings
  55.